package ru.jimbot.modules;

import ru.jimbot.protocol.AbstractProtocol;
import ru.jimbot.util.Log;




public class StartUins implements Runnable {
    private Thread th;
    private UINmanager um;  
    private int i=0;
   

    

    public StartUins(UINmanager um) {
       this.um = um;
    }
    
 
    public void start(){
        i=0;
        th = new Thread(this);
        th.setPriority(Thread.NORM_PRIORITY);
        th.start();
      
    }
    
    public synchronized void stop() {
        th = null;
        notify();
    }
    
    private void connect(){
        if (i<um.count()){
            ((AbstractProtocol)um.p.get(i)).connect();
             Log.info(i+"_Ожидаем "+(um.timeOut/1000)+"сек. и запускаем следующий аккаунт");
             i++;
        }else{
            stop();
        }
    }
    
    @Override
    public void run() {
       Thread me = Thread.currentThread(); 
        while (th == me) {
              connect();
            try {
                th.sleep(um.timeOut);
            } catch (InterruptedException e) { break; }             
        }
        th=null;
    }  
   
 }
